package com.Trainer.EvaluateInterface;

import javax.swing.*;
import java.awt.*;

public class EvaluateInterface extends JPanel {
    //属性
    JLabel pattern;
    JLabel difficulty;
    JLabel total;
    JLabel done;
    JLabel correct;
    JLabel time;
    JLabel correctRate;
    JLabel grade;
    JButton back;
    public EvaluateInterface(int width, int height){
        pattern=new JLabel("测验模式：");
        difficulty=new JLabel("难度：");
        total = new JLabel("总题数:");
        done = new JLabel("做题数:");
        correct = new JLabel("正确数:");
        time = new JLabel("用时:");
        correctRate = new JLabel("本轮正确率:");
        grade = new JLabel("评级：");
        back = new JButton("返回");

        //布局
        setBounds(0,0,width,height);
        setLayout(null);

        //标签修饰
        setLabel(pattern,200,30,200,40,32);
        setLabel(difficulty,480,30,200,40,32);
        setLabel(total,130,130,150,50,25);
        setLabel(done,290,130,150,50,25);
        setLabel(correct,450,130,150,50,25);
        setLabel(time,610,130,150,50,25);
        setLabel(correctRate,300,200,300,50,25);
        setLabel(grade,300,280,300,50,32);

        //按钮修饰
        back.setBounds(400,400,100,50);
        back.setFont(new Font("微软雅黑",Font.PLAIN,30));

        //添加组件
        add(pattern);
        add(difficulty);
        add(total);
        add(done);
        add(correct);
        add(time);
        add(correctRate);
        add(grade);
        add(back);
    }

    //方法
    public void setLabel(JLabel label, int x, int y, int weight, int height, int size){
        label.setBounds(x,y,weight,height);
        label.setOpaque(true);
        label.setFont(new Font("微软雅黑",Font.PLAIN,size));
        label.setHorizontalAlignment(SwingConstants.CENTER);
    }

    public JLabel getPattern() {
        return pattern;
    }

    public void setTotal(String total) {
        this.total.setText(this.total.getText()+total);
    }

    public void setDone(String done) {
        this.done.setText(this.done.getText()+done);
    }

    public void setCorrect(String correct) {
        this.correct.setText(this.correct.getText()+correct);
    }

    public void setTime(String time) {
        this.time.setText(this.time.getText()+time+"s");
    }

    public void setCorrectRate(String correctRate) {
        this.correctRate.setText(this.correctRate.getText()+correctRate+"%");
    }

    public void setGrade(String grade) {
        this.grade.setText(this.grade.getText()+grade);
    }

    public JButton getBack() {
        return back;
    }

    public void reset(String difficult){
        total.setText("总题数:");
        done.setText("做题数:");
        correct.setText("正确数:");
        time.setText("用时:");
        correctRate.setText("本轮正确率:");
        grade.setText("评级：");
        if (difficult.equals("420")){
            difficulty.setText("难度：简单");
        }else if (difficult.equals("300")){
            difficulty.setText("难度：一般");
        }else {
            difficulty.setText("难度：困难");
        }
    }
}
